from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import smtplib
import os

email_body='''
<h align="center">接口自动化测试报告 </h>
<p align="center">详情请见附件</p>
'''

email_text=MIMEText(email_body,'html','utf-8')

report_path=os.path.join(os.path.dirname(__file__),'..','html_reports','WX_TEST_API_V2.0','WX_TEST_API_V2.0.html')
attach_file=MIMEText(open(report_path,'rb').read(),'base64','utf-8')
attach_file['Content-type']='application/octet-stream'
attach_file.add_header('Content-Disposition','attachment',filename=('gbk','','WX_TEST_API_V2.0.html'))

email_obj=MIMEMultipart()
email_obj.attach(email_text)
email_obj.attach(attach_file)

email_obj['from']= '2428697515@qq.com'
email_obj['to']='2428697515@qq.com'
email_obj['Cc']='2428697515@qq.com'
email_obj['subject']='sunny123做的自动化测试报告'

smtp=smtplib.SMTP()
smtp.connect("smtp.qq.com")

smtp.login(user='2428697515@qq.com',password='ixfowsjfvbgcecaf')
smtp.sendmail('2428697515@qq.com','2428697515@qq.com',email_obj.as_string())
smtp.close()